package com.opensource.component.query.repository.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opensource.component.query.mapper.ExtendClickhouseBaseMapper;
import com.opensource.component.query.repository.ClickhouseExtendRepository;
import java.util.List;

/**
 * @author ZL since on 2021/12/18 下午9:23
 */
public abstract class AbstractClickhouseExtendRepositoryRepository<M extends ExtendClickhouseBaseMapper<T>, T> implements
    ClickhouseExtendRepository<T> {

  protected final M baseMapper;

  public AbstractClickhouseExtendRepositoryRepository(M baseMapper) {
    this.baseMapper = baseMapper;
  }

  @Override
  public List<T> loadClickhouseExtendList(Wrapper<T> wrapper) {
    return getBaseMapper().selectClickhouseListExtend(wrapper);
  }

  @Override
  public T loadClickhouseExtendOne(Wrapper<T> wrapper) {
    return getBaseMapper().selectClickhouseOneExtend(wrapper);
  }

  @Override
  public long loadClickhouseExtendCount(Wrapper<T> wrapper) {
    return getBaseMapper().selectClickhouseCountExtend(wrapper);
  }

  @Override
  public Page<T> loadClickhouseExtendPage(IPage<T> page, Wrapper<T> wrapper) {
    return getBaseMapper().selectClickhousePageExtend(page, wrapper);
  }

  @Override
  public ExtendClickhouseBaseMapper<T> getBaseMapper() {
    return baseMapper;
  }

  @Override
  public Class<T> getEntityClass() {
    return (Class<T>) ReflectionKit
        .getSuperClassGenericType(this.getClass(), AbstractClickhouseExtendRepositoryRepository.class, 1);
  }

}
